<template>
  <div></div>
</template>

<script>
export default {
  name: 'Jpush',
  data: function () {
    return {
      currJpushVip: null
    }
  },
  mounted () {
    let $this = this
    setTimeout(function () {
      $this.init()
    }, 2000)
  },
  methods: {
    // 初始化
    init: function () {
      let $this = this
      /* if (typeof plus !== 'undefined' && $this.CurrUser.IsLogin()) {
        console.log('个推初始化')
        var info = plus.push.getClientInfo()
        // alert('uni-push客户端信息: ' + JSON.stringify(info))
        // console.log('uni-push客户端信息内容: ',JSON.stringify(info))
        // prompt('token是: ',info.token)
        localStorage.setItem('TaPushToken',info.token)
        if ($this.CurrUser.IsLogin()){
          $this.MyRequest($this.ApiDoNameMember + 'Member/updateTaPushToken', {
            token:info.token
          }, function (data) {
            // $this.$refs['jpush'].setTag()
            $this.$forceUpdate()
          }, function (msg) {
            $this.$message.error(msg)
            // $this.form.password = ''
          })
        }

        // 消息被点击
        // plus.push.addEventListener('click', function (msg) {
        //   // 分析msg.payload处理业务逻辑
        //   alert('You clicked: ' + JSON.stringify(msg))
        // }, false)


        // 消息被点击后-穿透消息内容
        plus.push.addEventListener('receive', function (msg) {
          // 分析msg.content处理业务逻辑
          // alert('msg: ' + JSON.stringify(msg))
          if (msg.content && msg.content.length>2){
            var jsonData=JSON.parse(msg.content)
            $this.handlerMessage(jsonData)
          }
          // alert('msg2: ' + JSON.stringify(msg2))
        }, false)
      } */
    },
    // 处理不同类型消息
    handlerMessage: function (jsonData) {
      var toRoute=false
      let $this=this
      // 订单-消息
      if (jsonData.type==='ORDER'){
        if ($this.$route.name!=='OrderDetail'){
          toRoute=true
        }else{
          if ($this.$route.query.id!==jsonData.id){
            toRoute=true
          }else{
            $this.bus.$emit('OrderInfoUpdate',jsonData.id)
          }
        }
        if (toRoute){
          $this.$confirm('您是否前往查看该订单', '系统提示', {
            customClass:'my-confirm-box',
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            backType: 'warning'
          }).then(() => {
            // 跳转至订单详情
            $this.$router.push({
              name:'OrderDetail',
              query:{
                id:jsonData.id
              },
            })
          }).catch(() => {

          });
        }
      }


      // 退货订单-消息
      if (jsonData.type==='ORDER_APPLY'){
        if ($this.$route.name!=='OrderApply'){
          toRoute=true
        }else{
          if ($this.$route.query.id!==jsonData.id){
            toRoute=true
          }else{
            $this.bus.$emit('OrderApplyInfoUpdate',jsonData.id)
          }
        }
        if (toRoute){
          $this.$confirm('您是否前往查看该订单', '系统提示', {
            customClass:'my-confirm-box',
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            backType: 'warning'
          }).then(() => {
            // 跳转至【退换货订单】详情
            $this.$router.push({
              name:'OrderApply',
              query:{
                applyId:jsonData.id
              },
            })
          }).catch(() => {

          });
        }
      }
    }
  }
}
</script>
